package server.rest;

import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang.StringUtils;

public class RestfulHandlerConfig
{
    String schema;
    String method;
    boolean internal = true;
    boolean debug = false;

    ContentType requestContentType = ContentType.USER;
    ContentType responseContentType = ContentType.USER;
    SessionType sessionType = SessionType.NONE;

    String description;
    String heading;
    String[] requestParameters;
    String[] responseParameters;
    String[] urlParameters;
    int[] statusCodes;

    List<String> allowOptions = new ArrayList<String>();

    public RestfulHandlerConfig(String schema, String method, boolean internal, boolean debug, ContentType requestContentType, ContentType responseContentType, String description, String heading, String[] requestParameters, String[] responseParameters, String[] urlParameters, int[] statusCodes, SessionType sessionType)
    {
        super();
        this.schema = schema;
        this.method = method;
        this.internal = internal;
        this.debug = debug;
        this.requestContentType = requestContentType;
        this.responseContentType = responseContentType;
        this.description = description;
        this.heading = heading;
        this.requestParameters = requestParameters;
        this.responseParameters = responseParameters;
        this.urlParameters = urlParameters;
        this.statusCodes = statusCodes;
        this.sessionType = sessionType;
    }

    public RestfulHandlerConfig()
    {
        this("", "", true, false, ContentType.USER, ContentType.USER, "", "", null, null, null, null,SessionType.NONE);
    }

    public static RestfulHandlerConfig createHandlerConfig(String schema, String method, boolean internal,
                    boolean debug,
                    ContentType requestContentType, ContentType responseContentType, String description,
                    String heading, String[] requestParameters, String[] responseParameters, String[] urlParameters,
                    int[] statusCodes, SessionType sessionType)
    {
        return new RestfulHandlerConfig(schema, method, internal, debug, requestContentType, responseContentType,
                        description,
                        heading, requestParameters, responseParameters, urlParameters, statusCodes, sessionType);
    }

    public static RestfulHandlerConfig createHandlerConfig(Rest annotator)
    {
        return createHandlerConfig(annotator.schema(), annotator.method().toString(), annotator.internal(),
            annotator.debug(),
            annotator.requestContentType(), annotator.responseContentType(), annotator.description(),
            annotator.heading(), annotator.requestParameters(), annotator.responseParameters(),
            annotator.urlParameters(), annotator.statusCodes(),annotator.sessionType());
    }

    public String getSchema()
    {
        return schema;
    }

    public void setSchema(String schema)
    {
        this.schema = schema;
    }

    public String getMethod()
    {
        return method;
    }

    public void setMethod(String method)
    {
        this.method = method;
    }

    public boolean isInternal()
    {
        return internal;
    }

    public void setInternal(boolean internal)
    {
        this.internal = internal;
    }

    public boolean isDebug()
    {
        return debug;
    }

    public void setDebug(boolean debug)
    {
        this.debug = debug;
    }

    public ContentType getRequestContentType()
    {
        return requestContentType;
    }

    public void setRequestContentType(ContentType requestContentType)
    {
        this.requestContentType = requestContentType;
    }

    public ContentType getResponseContentType()
    {
        return responseContentType;
    }

    public void setResponseContentType(ContentType responseContentType)
    {
        this.responseContentType = responseContentType;
    }

    public String getDescription()
    {
        return description;
    }

    public void setDescription(String description)
    {
        this.description = description;
    }

    public String getHeading()
    {
        return heading;
    }

    public void setHeading(String heading)
    {
        this.heading = heading;
    }

    public String[] getRequestParameters()
    {
        return requestParameters;
    }

    public void setRequestParameters(String[] requestParameters)
    {
        this.requestParameters = requestParameters;
    }

    public String[] getResponseParameters()
    {
        return responseParameters;
    }

    public void setResponseParameters(String[] responseParameters)
    {
        this.responseParameters = responseParameters;
    }

    public String[] getUrlParameters()
    {
        return urlParameters;
    }

    public void setUrlParameters(String[] urlParameters)
    {
        this.urlParameters = urlParameters;
    }

    public int[] getStatusCodes()
    {
        return statusCodes;
    }

    public void setStatusCodes(int[] statusCodes)
    {
        this.statusCodes = statusCodes;
    }

    public List<String> getAllowOptions()
    {
        return allowOptions;
    }

    public void setAllowOptions(List<String> allowOptions)
    {
        this.allowOptions = allowOptions;
    }

    public void addAllowOption(String method)
    {
        if (StringUtils.isNotBlank(method))
        {
            getAllowOptions().add(method.toUpperCase());
        }
    }

    public SessionType getSessionType()
    {
        return sessionType;
    }

    public void setSessionType(SessionType sessionType)
    {
        this.sessionType = sessionType;
    }

}
